﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace UpdaterService.WinUI
{
    public partial class WinForm : Form
    {
        public WinForm()
        {
            InitializeComponent();            
            m_Downloader = new Updater.Common.Downloader();
            m_Downloader.Start();
        }

        Updater.Common.Downloader m_Downloader;

        private void stopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_Downloader.Stop();
            UpdateMenu(false);
        }

        private void UpdateMenu(bool isStartSelected)
        {
            sTopToolStripMenuItem.Enabled = isStartSelected;
            sTopToolStripMenuItem.Checked = !isStartSelected;
            startToolStripMenuItem.Checked = isStartSelected;
            startToolStripMenuItem.Enabled = !isStartSelected;
        }

        private void startToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_Downloader.Start();
            UpdateMenu(true);
        }

        private void WinForm_Load(object sender, EventArgs e)
        {
           notifyIcon.Visible = true;
            this.Visible = false;

        }

        private void WinForm_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void WinForm_Shown(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void WinForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            notifyIcon.Visible = false;
        }

        private void WinForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            notifyIcon.Visible = false;
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
